<table id="newart_data"></table>
<script>
$(function(){
	$.post("../json/newartInfoAction_getAllNewartInfo",{},function(data){
		$("#newart_naname option").remove();
		$("#newart_naContentImg").val("");
		var sltObj=$("#newart_naname");  //获取下拉对象
		var opt;
		$.each(data.rows,function(index,item){
			opt="<option value='"+item.naid+"'>"+item.naname+"</option>";
			sltObj.append($(opt));
		});
		$('#newart_data').datagrid({   
		    url:'../json/newartInfoAction_getNewart',
		    queryParams:{},
		    loadMsg:'数据加载中...',
		    pagination:true,
		    rownumbers:true,
		    fitColumns:true,
		  	sortName:'naid',
		  	sortOrder:'desc',
		  	remoteSort:false,
		    striped:true,
		    pageNumber:1,
		    pageSize:5, 
			pageList:[5,10,15,20,25,30,35,40,45,50],
		    columns:[[   
		    	{field:'naids',title:'',checkbox:true,width:50,align:'center'}, 
		        {field:'naid',title:'编号',width:50,align:'center',sortable:true},   
		        {field:'naname',title:'相册名称',width:150,align:'center'}, 
		        {title:'相册封面',field:'image',width:100,align:'center',
		        	formatter:function(value,row,index){return '<img width="80" height="100" src="../'+row.napic+'" />';}
		        },
		        {field:'nadate',title:'上传日期',width:100,align:'center'},
		        {field:'natime',title:'更新日期',width:100,align:'center'},
		        {field:'naContentImg',title:'相册中的照片',width:100,align:'center',formatter:function(value,rowData,index){
		        	return "<a class='icon-file icon-padding' href=\"javascript:showPicDetails('"+value+"')\">详细</a>";
		        }}  
		    ]],    
		        	
		    
		    toolbar: [{
		    	text:'添加相册',
				iconCls: 'icon-add',
				handler: function(){
					$("#newart_data_add").dialog("open");
				}
			},'-',{
		    	text:'添加照片',
				iconCls: 'icon-add',
				handler: function(){
					//var row=$("#newart_data").datagrid("getChecked")[0];
					//var naid=row.naid;
					
					$("#newart_data_pic_add").dialog("open");
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
					//获取所有被选中的行
					var rows=$("#newart_data").datagrid("getChecked");
					if(rows.length<=0){  //说明没有选中
						$.messager.show({
							title:'温馨提示',
							msg:'请选择您要删除的数据...',
							timeout:2000,
							showType:'slide'
						});
					}else{
						$.messager.confirm('信息确认', '您确定要删除选中的信息吗？', function(r){
							if (r){
								var naids="";
								//获取所有选中的数据的id
								for(var i=0;i<rows.length-1;i++){
									naids+=rows[i].naid+",";
								}
								naids+=rows[i].naid;
								
								//向服务器发送请求
								$.post("../json/newartInfoAction_delNewartInfo",{naids:naids},function(data){
									data=parseInt( $.trim(data.result) );
									if(data>0){
									$.messager.show({
										title:'成功提示',
										msg:'作品信息删除成功...',
										timeout:3000,
										showType:'slide'
									});
									$("#newart_data").datagrid("reload");
									}else{
										$.messager.alert('失败提示','作品信息删除失败，请稍后再试...','error');
									}
								});
							}
						});
					}
				}
			},'-',{
				text:'修改',
				iconCls: 'icon-edit',
				handler: function(){
					var rows=$("#newart_data").datagrid("getChecked");
					if(rows.length<=0){
						$.messager.show({
							title:'温馨提示',
							msg:'请选择您要修改的数据...',
							timeout:2000,
							showType:'slide'
						});
					}else{
						$("#newart_naname_update").val( rows[0].naname );
						$("#newart_naid_update").val( rows[0].naid );
						
						var naContentImg=rows[0].naContentImg;
						if(naContentImg.indexOf(",")){
							var arr=naContentImg.split(",");
							var str="";
							for(var i=0;i<arr.length;i++){
								if(arr[i]!="暂无"){
									var imgId="img_"+i;
									str+='<a href="javascript:delPic('+i+')"><img id="'+imgId+'" src="../'+arr[i]+'" style="width:100px;height:100px;float:left; margin:10px 0px 0px 10px;" /></a>';
								}
							}
						}
						$("#newart_update_pic").html(str);
						$("#newart_data_update").dialog("open");
					}
				}
			}]
		});
		
		$("#newart_data").datagrid('getPager').pagination({
			beforePageText:'第',
			afterPageText:'页 共{pages}页',
			displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录'
		});
	},"json");
	  
})

function delPic(id){
	var src=$('#img_'+id).attr('src');
	src=src.substr(src.indexOf("/")+1);
	var naid=$("#newart_naid_update").val();
	
	$.post("../json/newartInfoAction_updateNewartPic",{src:src,naid:naid},function(data){
		data=parseInt( $.trim(data.result) );
		if(data>0){
			$.messager.confirm('信息确认', '您确定要删除此照片吗？', function(r){
				if (r){
					$('#img_'+id).css("display","none");
				}
			});
		}else{
			$.messager.alert('失败提示','照片信息删除失败，请稍后再试...','error');
		}
	});
}

function newart_updateInfo(){
	var naid=$("#newart_naid_update").val();
	var naname=$("#newart_naname_update").val();
	
	$.post("../json/newartInfoAction_updateNewartInfo",{naid:naid,naname:naname},function(data){
		data=parseInt( $.trim(data.result) );
		if(data>0){
			$.messager.show({
				title:'成功提示',
				msg:'作品信息修改成功...',
				timeout:3000,
				showType:'slide'
			});
			$("#newart_data_update").dialog("close");
			$("#newart_data").datagrid("reload");
		}else{
			$.messager.alert('失败提示','作品信息修改失败，请稍后再试...','error');
		}
	});
}

function showPicDetails(value){
	var naContentImg=value;
	
	if(naContentImg.contains(",")){
		var arr=naContentImg.split(",");
		var str="";
		for(var i=0;i<arr.length;i++){
			if(arr[i]!="暂无"){
				var imgId="img_"+i;
				str+='<img id="'+imgId+'" src="../'+arr[i]+'" style="width:100px;height:100px;float:left; margin:10px 0px 0px 10px;" />';
			}
		}
	}
	$("#newart_data_pic_show").html(str);
	$("#newart_data_pic_show").dialog("open");
}

function qq(value,name){   
	//alert(value+":"+name) ;
	    
	$.post("../json/newartInfoAction_getNewartByxx",{value:value,name:name},function(data){
		data=parseInt( $.trim(data.total) );
		if(data>0){
			$("#newart_data").datagrid("reload");
		}else{
			$.messager.alert('失败提示','没有您要查的数据，请再次确认要查的数据...','error');
		}
	});
}   

</script>

<div style="position:absolute;top:65px;left:850px;"> 
	<input id="ss" class="easyui-searchbox" style="width:300px"  
	        data-options="searcher:qq,prompt:'Please Input Value',menu:'#mm'"></input>  
	           
	<div id="mm" style="width:120px">  
	    <div data-options="name:'naname',iconCls:'icon-ok'">相册名称</div>  
	    <div data-options="name:'natime'">更新日期</div>  
	</div>  
</div> 
<div id="newart_data_add" class="easyui-dialog" title="添加作品信息" style="width:400px;height:200px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
    <br/>  <br/> 
    <center>
    	<form>
    	<label for="newart_naName">相册名：</label><input name="naname" type="text" id="newart_naName" />  <br/>  <br/> 
    	<label for="file" style="padding-left:28px;">相册封面图片：</label><input name="file" type="file" id="file"/>  <br/>  <br/> 
    	<!--<label for="newart_naContentImg">相册照片：</label><input name="naContentImg" id="newart_naContentImg" type="file" multiple="multiple" onchange="previewMultipleImage(this,'newart_show_pic')"/>  <br/>   		
   		-->
   		<a href="javascript:addNewartInfo()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
   		</form>
   		
   		<!-- <div id="newart_show_pic" style="float:right;width:330px;height:800px;border:1px solid #ef6819;margin-right:10px;">
   		
   		</div> -->
    </center>
</div>  

<div id="newart_data_pic_add" class="easyui-dialog" title="添加作品照片" style="width:400px;height:600px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
    <br/>  <br/> 
    <center>
    	<form>
    	<label>相册名：</label> 
    	<select name="naname" style="width:200px;height:24px" id="newart_naname">
    	
    	</select><br/>
    	<label for="myfile">相册照片：</label><input name="myfile" id="myfile" type="file" multiple="multiple" onchange="previewMultipleImage(this,'newart_show_pic')"/>  <br/>   		
   		
   		<a href="javascript:addNewartPic()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
   		</form>
   		
   		<div id="newart_show_pic" style="float:right;width:330px;height:500px;border:1px solid #ef6819;margin-right:10px;">
   	
   		</div>
    </center>
</div>  

<div id="newart_data_update" class="easyui-dialog" title="修改作品信息" style="width:800px;height:400px;" data-options="iconCls:'icon-edit',resizable:true,modal:true,closed:true">  
    <br/>  <br/> 
    <center>
    	<input type="hidden" id="newart_naid_update" /> 
    	<label for="newart_naname_update">封面图片名：</label><input type="text" id="newart_naname_update" />  <br/>  <br/> 
   		
   		<label style="">作品中的照片：</label>
   		<div id="newart_update_pic" style="width:668px;height:400px;border:1px solid #ef6819;margin-right:10px;">
   	
   		</div>
   		
   		<input type="button" onclick="newart_updateInfo()" value="修改" style="clear:both;"/>
    </center>
</div>  

<div id="newart_data_pic_show" class="easyui-dialog" title="作品照片详细" style="width:685px;height:400px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
    
</div>  

<script>
	//实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    //var ue = UE.getEditor('editor');
    
    function addNewartInfo(){
    	var naname=$("#newart_naName").val();
    	//var napic=$("#newart_naPic").val();
    	//var naContentImg=$("#newart_naContentImg").val();
    	
    	$.ajaxFileUpload({
    		url:"../struts2/newartInfoAction_addNewartInfo",//用于文件上传的服务器端请求地址
    		secureuri:false,
    		//fileElementId:["newart_naPic","newart_naContentImg"],
    		fileElementId:"file", // 文件上传控件的id属性 
    		dataType:"json",
    		data:{"newartInfo.naname":naname},
    		success:function(data,status){
    			if(parseInt($.trim(data.jsonObject.result))==1){
    				$.messager.show({
    					title:'成功提示',
						msg:'作品信息上传成功...',
						timeout:2000,
						showType:'slide'
    				});
    				$("#newart_naName").val("");
    				$("#newart_naPic").val("");
    				$("#newart_data_add").dialog("close");
    				$("#newart_data").datagrid("reload");
    				
    				//重新刷次下拉列表
    				$.post("../json/newartInfoAction_getAllNewartInfo",{},function(data){
    					$("#newart_naname option").remove();
    					$("#newart_naContentImg").val("");
    					var sltObj=$("#newart_naname");  //获取下拉对象
    					var opt;
    					$.each(data.rows,function(index,item){
    						opt="<option value='"+item.naid+"'>"+item.naname+"</option>";
    						sltObj.append($(opt));
    					});
    				},"json");
    			}else{
    				$.messager.alert('失败提示','作品信息添加失败，请稍后再试...','error');
    			}
    		},
    		error:function(data,status,e){
    			$.messager.alert('失败提示','作品信息添加失败，请稍后再试...','error');
    		}
    	},"json");
    }
    
    function addNewartPic(){
    	var naid=$("#newart_naname").val();
    	
    	$.ajaxFileUpload({
    		url:"../struts2/newartInfoAction_addNewartPic",//用于文件上传的服务器端请求地址
    		secureuri:false,
    		fileElementId:"myfile", // 文件上传控件的id属性 
    		dataType:"json",
    		data:{"newartInfo.naid":naid},
    		success:function(data,status){
    			if(parseInt($.trim(data.jsonObject.result))==1){
    				$.messager.show({
    					title:'成功提示',
						msg:'作品信息上传成功...',
						timeout:2000,
						showType:'slide'
    				});
    				$("#newart_naContentImg").val("");
    				$("#newart_show_pic").html("");
    				$("#newart_data_pic_add").dialog("close");
    				$("#newart_data").datagrid("reload");
    			}else{
    				$.messager.alert('失败提示','作品信息添加失败，请稍后再试...','error');
    			}
    		},
    		error:function(data,status,e){
    			$.messager.alert('失败提示','作品信息添加失败，请稍后再试...','error');
    		}
    	},"json");
    }
</script>